/*********************************************************************
	\file :           os_sw_layers\bios\services\scheduler\Os_Isr.c
	\brief:           Provide the configured tasks to the application
	\author:          Manuel Sandoval
	\version:         1.0
	\date:            Sat, 01, March 2014
*********************************************************************/

/******************************* Includes**********************************/

#include "Os_Isr.h"
#include "Mcu.h"
#include "SchM.h"
#include "Os_TaskM.h"
#include "Fifo_queue.h"


/******************************* Defines **********************************/

/******************************* Enumerations******************************/


/******************************* Structures *******************************/


/******************************* Global Variables **********************************/
Os_TaskStack stOs_ISRMainStack;
extern queue Os_Fifo;
Os_TaskControlBlockType Os_Task_temp;
  
/******************************* Prototypes ********************************/


/******************************* Functions ********************************/

#pragma CODE_SEG __NEAR_SEG NON_BANKED


/***************************************************************************
*
*   FUNCTION NAME: ISR(OsTick)
*
***************************************************************************/
/**
* @brief Provides a single interface to Activate a OsTick ISR.
*
*
* @param[in] none.
* @param[in] none.
*
* @return void.
*
* None.
*
***************************************************************************/
ISR(OsTick)
{
  if( PITTF_PTF0 == 1u )
  {
    PITTF_PTF0 = 1u;
  }
  SchM_OsTick();  
}/* ISR(OsTick) */

/***************************************************************************
*
*   FUNCTION NAME: ISR(PITCh1)
*
***************************************************************************/
/**
* @brief Provides a single interface to Activate a PITCh1 ISR.
*
*
* @param[in] none.
* @param[in] none.
*
* @return void.
*
* None.
*
***************************************************************************/
ISR(PITCh1)
{
  vfnSaveTaskContext(&stOs_ISRMainStack);
   
  PITTF_PTF1 = 1u;
  
  
  if(E_OK == ActivateTask(Os_Tasks_Config[TASK_PITCh1].TaskId))
  {
	Os_Task_temp.TaskId = Os_Tasks_Config[TASK_PITCh1].TaskId;
	Os_Task_temp.TaskPriority = Os_Tasks_Config[TASK_PITCh1].TaskPriority;
	Os_Task_temp.TaskState = RUNNING;
	
  	dequeue(&Os_Fifo, &Os_Task_temp);

  }
  
  vfnRunISRRoutine();      
} /* ISR(PITCh1) */


/***************************************************************************
*
*   FUNCTION NAME: ISR(PITCh2)
*
***************************************************************************/
/**
* @brief Provides a single interface to Activate a PITCh2 ISR.
*
*
* @param[in] none.
* @param[in] none.
*
* @return void.
*
* None.
*
***************************************************************************/
ISR(PITCh2)
{
  vfnSaveTaskContext(&stOs_ISRMainStack);
   
  PITTF_PTF2 = 1u;
  
  if(E_OK == ActivateTask(Os_Tasks_Config[TASK_PITCh2].TaskId))
  {
  	Os_Task_temp.TaskId = Os_Tasks_Config[TASK_PITCh2].TaskId;
	Os_Task_temp.TaskPriority = Os_Tasks_Config[TASK_PITCh2].TaskPriority;
	Os_Task_temp.TaskState = RUNNING;
	
  	dequeue(&Os_Fifo, &Os_Task_temp);

  }
  
  vfnRunISRRoutine();   
} /* ISR(PITCh2) */


/***************************************************************************
*
*   FUNCTION NAME: ISR(PP0)
*
***************************************************************************/
/**
* @brief Provides a single interface to Activate a PP0 ISR.
*
*
* @param[in] none.
* @param[in] none.
*
* @return void.
*
* None.
*
***************************************************************************/
ISR(PP0)
{
  vfnSaveTaskContext(&stOs_ISRMainStack);
  
  if(E_OK == ActivateTask(Os_Tasks_Config[TASK_PP0].TaskId))
  {
    Os_Task_temp.TaskId = Os_Tasks_Config[TASK_PP0].TaskId;
	Os_Task_temp.TaskPriority = Os_Tasks_Config[TASK_PP0].TaskPriority;
	Os_Task_temp.TaskState = RUNNING;
	
  	dequeue(&Os_Fifo, &Os_Task_temp);

  }
  
  vfnRunISRRoutine();
  
}/* ISR(PP0) */


/***************************************************************************
*
*   FUNCTION NAME: ISR(PP1)
*
***************************************************************************/
/**
* @brief Provides a single interface to Activate a PP1 ISR.
*
*
* @param[in] none.
* @param[in] none.
*
* @return void.
*
* None.
*
***************************************************************************/
ISR(PP1)
{
  vfnSaveTaskContext(&stOs_ISRMainStack);
  
  if(E_OK == ActivateTask(Os_Tasks_Config[TASK_PP1].TaskId))
  {
    Os_Task_temp.TaskId = Os_Tasks_Config[TASK_PP1].TaskId;
	Os_Task_temp.TaskPriority = Os_Tasks_Config[TASK_PP1].TaskPriority;
	Os_Task_temp.TaskState = RUNNING;
	
  	dequeue(&Os_Fifo, &Os_Task_temp);

  }
  
  vfnRunISRRoutine(); 
} /* ISR(PP1) */


#pragma CODE_SEG DEFAULT



/** @} *//* End of Scheduler ISRs Group */